//
//  WBWelcomeView.swift
//  Weibo
//
//  Created by wade on 17/3/7.
//  Copyright © 2017年 wade. All rights reserved.
//

import UIKit

class WBWelcomeView: UIView {

    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLab: UILabel!
    
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    class func setupWBWelcomeView() -> WBWelcomeView{
        
        let nib = UINib(nibName: "WBWelcomeView", bundle: nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WBWelcomeView

        v.frame = UIScreen.main.bounds
        
        return v
    }
    
    override func awakeFromNib() {
        
        guard let urlstr = WBNetworkManager.shared.userAccount.avatar_large,
            let url = URL(string:urlstr) else {
            
                return
        }
        
        iconView.setImageWith(url, placeholderImage: UIImage(named: "avatar_default_big"))
        
        iconView.layer.cornerRadius = 42.5
        iconView.layer.masksToBounds = true
        
    }
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        
        self.layoutIfNeeded()
        
        bottomCons.constant = UIScreen.main.bounds.height - 200
        
        UIView.animate(withDuration: 2.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 0.5, animations: {
                self.tipLab.alpha = 1
            }){(_) in
                
                self.removeFromSuperview()
            
            }
        }
        
    }
    

}
